# -*- encoding:utf8 -*-

from django.utils import timezone
from convert import dt2str
from models import MsgModel
import weixin

def send_msg(staff, content, title='untitled', category='normal'):
    """发送消息
    @type staff :StaffInfo 员工
    @type content: str 内容
    @type title:str 标题
    @type category: str 类型
    """
    if staff:
        now_str = dt2str(timezone.localtime(timezone.now()))
        check_msg =MsgModel(staff=staff, title=title, category=category, content=content, gen_time=now_str)
        check_msg.save()
        weixin.send_text(staff.employee_id, \
            '有一个假期申请需要您处理http://wechat.mokitech.com/attendance/weixin/approve.html#/?id=%s'%check_msg.id)
        return True
    else:
        return False